/**
 * Created with JetBrains WebStorm.
 * User: liyong.wang
 * Date: 2017/11/3
 * Time: 上午10:08
 * Desc: 首页顶部header以及左边菜单逻辑
 */
;

(function(){
    /**
     * 删除cookie
     * @param objName
     * @param objDomain
     * @returns {string}
     */
    function deleteCookie(objName, objDomain) {
        return document.cookie = objName + "=;path=/;domain=" + objDomain + ";expires=" + (new Date(0)).toGMTString();
    }
    //菜单事件
    $('.second-level').on('click',function(){
        if($(this).hasClass('active')){return;}
        $('.second-level').removeClass('active');
        $(this).addClass('active');
    });
    $('.third-level a').on('click',function(){
        if($(this).hasClass('active')){return;}
        $('.third-level a').removeClass('active');
        $(this).addClass('active');
    });

    /*默认选中菜单逻辑  刷新页面后菜单选中逻辑*/
    var hashCode = window.location.hash;
    $('.second-level').removeClass('active');
    $('.third-level a').removeClass('active');
    $('.third-level a[href="'+hashCode+'"]').addClass('active').parents('.second-level').addClass('active');

    /*退出登录、切换账号*/
    $("#changeAccount,#notLogin").on("click",function () {
        deleteCookie("token",document.domain)
        deleteCookie("branchCode",document.domain)
        deleteCookie("stationCode",document.domain)
        deleteCookie("stationLevel",document.domain)
        window.location.href = '/login.html'
    })
    /**
     * 点击图片放大
     */
    $('body').on('click', '.js-magnify-img', function() {
        var $this = $(this), src = $this.attr('src'), html = [];
        if(!src) {
            return;
        }
        html.push('<div class="magnify-img-wrap">');
        html.push('<div class="magnify-img-inner"><img src="' + src + '" /></div>')
        html.push('</div>');
        $('body').append(html.join(''));
    })
        .on('click', '.magnify-img-wrap', function() {
            var $this = $(this);
            $this.hide(100, function() {
                $this.remove();
            })
        });
})();